﻿using System;
using System.Net.Sockets;

namespace ClownStopper
{
    /// <summary>
    /// 
    /// </summary>
    /// <by>Dan Turco</by>
    /// <created>2/21/2011</created>
    /// <revised></revised>
    public class TxRxPacket
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="TxRxPacket"/> class.
        /// </summary>
        /// <param name="socket">The socket.</param>
        /// <by>Dan Turco</by>
        /// <created>2/21/2011</created>
        /// <revised></revised>
        public TxRxPacket(Socket socket)
        {
            mCurrentSocket = socket;
            mDataBuffer = new Byte[1024];
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="TxRxPacket"/> class.
        /// </summary>
        /// <param name="socket">The socket.</param>
        /// <param name="bufferSize">Size of the buffer.</param>
        /// <by>Dan Turco</by>
        /// <created>2/21/2011</created>
        /// <revised></revised>
        public TxRxPacket(Socket socket, int bufferSize)
        {
            mCurrentSocket = socket;
            mDataBuffer = new Byte[bufferSize];
        }

        /// <summary>
        /// Stores the current data.
        /// </summary>
        /// <by>Dan Turco</by>
        /// <created>2/21/2011</created>
        /// <revised></revised>
        public void StoreCurrentData()
        {
            int storedBufferLength = (mStoredBuffer != null) ? mStoredBuffer.Length : 0;
            byte[] newBuffer = new byte[storedBufferLength + mDataBuffer.Length];
            for (int i = 0; i < storedBufferLength; ++i)
            {
                newBuffer[i] = mStoredBuffer[i];
            }
            for (int i = 0; i < mDataBuffer.Length; ++i)
            {
                newBuffer[storedBufferLength + i] = mDataBuffer[i];
            }
            mStoredBuffer = newBuffer;
            mDataBuffer = null;
            mDataBuffer = new Byte[1024];
        }

        public Socket mCurrentSocket;
        public Byte[] mDataBuffer;
        public Byte[] mStoredBuffer;
    }
}
